home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.07 Nov⁄Dec 92 / Function Logging / Code / LogOopTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-29  |  2.1 KB  |  139 lines  |  [TEXT/KAHL]

  1. /*
  2.     LogOopTest.c - A simple object-oriented test of the logging system.
  3. */
  4.  
  5. #include "LogToFile.h"
  6. #include <Memory.h>
  7. #include <QuickDraw.h>
  8. #include <Fonts.h>
  9. #include <Windows.h>
  10. #include <Menus.h>
  11. #include <TextEdit.h>
  12. #include <Dialogs.h>
  13. #include <OSEvents.h>
  14. #include <oops.h>
  15.  
  16. /*
  17.     This #pragma indicates that all functions in this file will be logged.
  18.     You can move it to a single routine to log just that routine.
  19.         #pragma options( profile, force_frame )
  20.  
  21.     The opposite of this command is:
  22.         #pragma options( !profile, !force_frame ) 
  23. */
  24. #pragma options( profile, force_frame )
  25.  
  26.  
  27. class BaseClass : indirect
  28. {
  29.     public:
  30.         BaseClass();
  31.         ~BaseClass();
  32.         short MiscFunc( short x );
  33. };
  34.  
  35. class ChildClass : BaseClass
  36. {
  37.     public:
  38.         ChildClass();
  39.         ~ChildClass();
  40.         short MiscFunc( short x );
  41. };
  42.  
  43.  
  44. /*
  45.     Other prototypes
  46. */
  47. void    InitMacToolbox( void );
  48. void     DoSomeOopStuff( void );
  49.  
  50. main()
  51. {
  52.     InitMacToolbox();
  53.     
  54.     /*
  55.         initialize the logging system
  56.     */
  57.     LogInit( NULL,         // default file location
  58.             true,         // delete the old file
  59.             false,         // don't flush the volume all the time
  60.             true );        // start logging
  61.  
  62.     DoSomeOopStuff();
  63.  
  64.     /*
  65.         Close the log file
  66.     */
  67.     LogDInit();
  68. }
  69.  
  70. void DoSomeOopStuff( void )
  71. {
  72.     ChildClass    *p;
  73.     
  74.     /*
  75.         Create an instance of ChildClass. This will call both constructors.
  76.     */
  77.     p = new( ChildClass );
  78.     if ( !p ) return;
  79.  
  80.     /*
  81.         The logger will show whether ChildClass::MiscFunc or BaseClass::MiscFunc
  82.         is being called.
  83.     */
  84.     p->MiscFunc( 5 );
  85.     
  86.     /*
  87.         Destroy the object. This will call both destructors.
  88.     */
  89.     delete( p );
  90. }
  91.  
  92.     // constructor
  93. BaseClass::BaseClass()
  94. {
  95. }
  96.  
  97.     // destructor
  98. BaseClass::~BaseClass()
  99. {
  100. }
  101.  
  102.     // some method
  103. short BaseClass::MiscFunc( short x )
  104. {
  105.     return( x*2 );
  106. }
  107.  
  108.     // constructor
  109. ChildClass::ChildClass()
  110. {
  111. }
  112.  
  113.     // destructor
  114. ChildClass::~ChildClass()
  115. {
  116. }
  117.     
  118.     // override MiscFunc
  119. short ChildClass::MiscFunc( short x )
  120. {
  121.     x = inherited::MiscFunc( x );
  122.     return( x );
  123. }
  124.  
  125.  
  126. static void InitMacToolbox( void )
  127. {
  128.     MaxApplZone();
  129.     MoreMasters(); MoreMasters();
  130.     InitGraf( &qd.thePort ); 
  131.     InitFonts();
  132.     InitWindows();
  133.     InitCursor();
  134.     InitMenus();
  135.     InitDialogs( 0L );
  136.     TEInit();
  137.     FlushEvents( -1, 0 );    
  138. }
  139.